package com.ydcycloud.sys.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.smart.sso.rpc.Permissionable;
import com.ydcycloud.admin.model.Manager;
import com.ydcycloud.admin.service.ManagerService;
import com.ydcycloud.sys.model.SessionAdmin;

public abstract class BaseAdminController extends BaseController {

	@Resource
	protected ManagerService managerService;

	/**
	 * Description:获取session中保存的当前登录用户
	 * 
	 * @author 唐海洋
	 * @Version 1.0 2015-9-19下午3:11:26
	 * @return
	 */
	protected SessionAdmin getSessionAdmin(HttpSession httpSession) {

		SessionAdmin sessionAdmin = (SessionAdmin) httpSession
				.getAttribute("sessionAdmin");
		if (sessionAdmin == null) {
			Manager manager = new Manager();
			manager.setId(1);
			String loginName = (String) httpSession
					.getAttribute(Permissionable.SESSION_ACCOUNT);
			manager.setName(loginName == null ? "未知" : loginName);
			sessionAdmin = new SessionAdmin(manager.getId(), manager.getName());
			httpSession.setAttribute("sessionAdmin", sessionAdmin);

		}

		return sessionAdmin;
	}

	/**
	 * 
	 * 获取当前登录者id
	 * 
	 * @Description: TODO
	 * @param @param httpSession
	 * @param @return
	 * @return Integer
	 * @throws
	 * @author yzw
	 * @date 2016年12月7日
	 */
	protected Integer getSessionAdminId(HttpSession httpSession) {
		SessionAdmin sessionAdmin = getSessionAdmin(httpSession);
		if (sessionAdmin == null) {
			Manager manager = new Manager();
			manager.setId(1);
			String loginName = (String) httpSession
					.getAttribute(Permissionable.SESSION_ACCOUNT);
			manager.setName(loginName == null ? "未知" : loginName);
			sessionAdmin = new SessionAdmin(manager.getId(), manager.getName());
			httpSession.setAttribute("sessionAdmin", sessionAdmin);

		}
		return sessionAdmin.getId();
	}
}
